package com.es.hr.emp;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.es.main.LoginUserBeen;
import com.es.util.common.CityBean;
import com.es.util.common.CommonBiz;
import com.es.util.format.Format;
import com.opensymphony.webwork.interceptor.ServletRequestAware;
import com.opensymphony.webwork.interceptor.ServletResponseAware;
import com.opensymphony.xwork.ActionSupport;

@SuppressWarnings("serial")
public class AjaxGetCityListAction  extends ActionSupport implements ServletRequestAware, ServletResponseAware{
	
	  HttpServletRequest request;
	  HttpServletResponse response;

	  public String execute() throws Exception
	  {
		  CommonBiz biz = new CommonBiz((LoginUserBeen)request.getSession(false).getAttribute("loginuser"));
		  String queryAreaCode = request.getParameter("queryAreaCode").trim();
		  ArrayList<CityBean> pro = biz.getCityList(queryAreaCode);
		  HashMap<String,List<String>> map = new HashMap<String,List<String>>();
		  List<String> list = new ArrayList<String>();
		  
		  for (CityBean city : pro) {
			  list.add(city.getCityCode()+","+city.getCityName());
		  }
		  map.put("city", list);
	      String returnTxt = Format.createResponseMessageAsXML(map);
	      this.response.setContentType("text/xml;charset=utf-8");
	      this.response.getWriter().write(returnTxt);
	      return "";
	  }

	  public void setServletRequest(HttpServletRequest request) {
	    this.request = request;
	  }

	  public void setServletResponse(HttpServletResponse response) {
	    this.response = response;
	  }
	}